package com.example.demo.createanddestroyobjects.one.one2;

/**
 * 构建器 用来优化构造器
 */
public class Demo2 {
    private final int size;
    private final int fat;
    private final int so;

    public static class Builder{
        private final int size;
        private final int fat;
        private int so = 0;

        public Builder(int size, int fat) {
            this.size = size;
            this.fat = fat;
        }

        public Builder so(int val) {
            so = val;
            return this;
        }

        public Demo2 build() {
            return new Demo2(this);
        }
    }

    private Demo2(Builder builder) {
        size = builder.size;
        fat = builder.fat;
        so = builder.so;
    }


    public static void main(String[] args) {
        //内部类 构建器的使用

        Demo2 builder = new Demo2.Builder(240,8)
                .so(5).build();
        System.out.println(builder.fat);
    }
}
